
class CFList {
	private:
	int MAXNISO;
	vtkAlgorithmOutput *input;
	int nIso;
	double *isoValues;
	double **isoColors;
	double *opacities;
	vtkContourFilter **list;
		
	public:
	CFList(vtkAlgorithmOutput *input, int nMax = 10);
	void AddIsoValue(double isoValue, double r = 0, double g = 0, double b = 0, double opac = 1.0);
	void DelIsoValue(int n);
	void EditIsoValue(double isoValue, int n);
	vtkAlgorithmOutput * GetOutput(int n = 0);
	int GetnIso();
	double GetIsoValue(int n = 0);
	double GetIsoOpacity(int n = 0);
	double * GetIsoColor(int n = 0);
	void UpdateInput(vtkAlgorithmOutput *input);
};

void CFList::UpdateInput(vtkAlgorithmOutput *newinput) {
	for(int i = 0; i < nIso; i++) {
		list[i]->SetInputConnection(newinput);
	}
}

double CFList::GetIsoOpacity(int n) {
	return opacities[n];
}

void CFList::EditIsoValue(double isoValue, int n) {
	isoValues[n] = isoValue;
	list[n]->SetValue(0, isoValue);
}

CFList::CFList(vtkAlgorithmOutput *output, int nMax) : MAXNISO(nMax) {
	list = new vtkContourFilter*[MAXNISO];
	isoValues = new double[MAXNISO];
	isoColors = new double*[MAXNISO];
	opacities = new double[MAXNISO];
	for(int i = 0; i < MAXNISO; i++) isoColors[i] = new double[3];
	nIso = 0;
	input = output;
}

vtkAlgorithmOutput * CFList::GetOutput(int n) {
	return list[n]->GetOutputPort();
}
	

void CFList::AddIsoValue(double isoValue, double r, double g, double b, double opac) {
	vtkContourFilter *CF = vtkContourFilter::New();
	CF->SetInputConnection(input);
	CF->SetValue(0, isoValue);
	CF->UseScalarTreeOn();
	CF->ComputeScalarsOn();
	list[nIso] = CF;
	isoValues[nIso] = isoValue;
	isoColors[nIso][0] = r;
	isoColors[nIso][1] = g;
	isoColors[nIso][2] = b;
	opacities[nIso] = opac;
	nIso++;
}

void CFList::DelIsoValue(int n) {
	list[n]->Delete();
	for(int i = n; i < nIso; i++) {
		list[i] = list[i+1];
		isoValues[i] = isoValues[i+1];
		isoColors[i][0] = isoColors[i+1][0];
		isoColors[i][1] = isoColors[i+1][1];
		isoColors[i][2] = isoColors[i+1][2];
		opacities[i] = opacities[i+1];
	}
	nIso--;
}

int CFList::GetnIso() {
	return nIso;
}

double CFList::GetIsoValue(int n) {
	return isoValues[n];
}
	
double * CFList::GetIsoColor(int n) {
	double *colorCopy = new double[3];
	colorCopy[0] = isoColors[n][0];
	colorCopy[1] = isoColors[n][1];
	colorCopy[2] = isoColors[n][2];
	return colorCopy;
}
